package com.charging.business.media;

import com.charging.business.utils.ToolsUtil;

/**
 * CPC卡计费信息文件中过省信息的编码信息
 * @author lzj
 */
public class CpcProvEdModel {
    public static final int MSG_LEN = 23;

    /**
     * 省份行政区域编码(01-01,1,cn)
     * 样例:0x41
     */
    public byte[] provinceId = new byte[1];

    /**
     * 本省ETC门架通行个数(02-02,1,n)
     */
    public byte[] gantryCount = new byte[1];

    /**
     * 本省累计金额(03-05,3,n)
     */
    public byte[] provSumPayFee = new byte[3];

    /**
     * 本省累计计费里程(06-08,3,n)
     */
    public byte[] sumMileage = new byte[3];

    /**
     * 本省入口编码(09-11,3,bn)
     * 样例:0x432233
     */
    public byte[] provEntryHex = new byte[3];

    /**
     * 本省入口时间(12-15,4,n)UNIX时间
     */
    public byte[] enTime = new byte[4];

    /**
     * 本省最新门架(16-18,3,bn)
     * 样例:0x412233
     */
    public byte[] newGantryNo = new byte[3];

    /**
     * 本省最新通过时间(19-22,4,n)UNIX时间
     */
    public byte[] newGantryTime = new byte[4];

    /**
     * 本省最新门架拟合标识(23-23,1,bn)
     * 0x00-成功; 0x01-失败
     */
    public byte[] newGantryFitting = new byte[1];

    public static CpcProvEdModel parse(byte[] buff, int staPos) {
        int index = staPos;
        CpcProvEdModel ret = new CpcProvEdModel();
        index += ToolsUtil.arrcopy(buff, index, ret.provinceId);
        index += ToolsUtil.arrcopy(buff, index, ret.gantryCount);
        index += ToolsUtil.arrcopy(buff, index, ret.provSumPayFee);
        index += ToolsUtil.arrcopy(buff, index, ret.sumMileage);
        index += ToolsUtil.arrcopy(buff, index, ret.provEntryHex);
        index += ToolsUtil.arrcopy(buff, index, ret.enTime);
        index += ToolsUtil.arrcopy(buff, index, ret.newGantryNo);
        index += ToolsUtil.arrcopy(buff, index, ret.newGantryTime);
        index += ToolsUtil.arrcopy(buff, index, ret.newGantryFitting);

        return ret;
    }

    public static CpcProvEdModel parse(String strHex) {
        byte[] buff = ToolsUtil.hex2bin(strHex);
        return parse(buff, 0);
    }

    /**
     * 信息解码
     *
     * @return
     */
    public CpcProvModel decoded() {
        CpcProvModel dd = new CpcProvModel();
        dd.provinceId = ToolsUtil.bin2hex(provinceId);
        dd.gantryCount = ToolsUtil.bin2int(gantryCount);
        dd.provSumPayFee = ToolsUtil.bin2int(provSumPayFee);
        dd.sumMileage = ToolsUtil.bin2int(sumMileage);
        dd.provEntryHex = ToolsUtil.bin2hex(provEntryHex);
        dd.enTime = ToolsUtil.bin2lng(enTime);
        dd.newGantryNo = ToolsUtil.bin2hex(newGantryNo);
        dd.newGantryTime = ToolsUtil.bin2lng(newGantryTime);
        dd.newGantryFitting = ToolsUtil.bin2int(newGantryFitting);

        return dd;
    }
}
